$(function(){
    doDefault(doShareFriend);
})

//获取微信jssdk凭证
function doDefault(successCallBack,errorCallBack) {
    var successCallBack=successCallBack||false; 
    var errorCallBack=errorCallBack||false; 
    $.ajax({
        type: "post",
        url: "CommonApi/CommonWx/getWxJsSdkConfig",
        data: {
            url: window.location.href,
            park_id:$('#park_id').val()
        },
        async: true,
        dataType: 'json',
        success: function(data) {
            if (data.status) {
                var t = JSON.parse(data.v);
                wx.config({
                    beta: true,
                    debug: false,
                    appId: t.appId,
                    timestamp: t.timestamp,
                    nonceStr: t.nonceStr,
                    signature: t.signature,
                    jsApiList: ['checkJsApi',"onMenuShareTimeline", "onMenuShareAppMessage"] // 必填，需要使用的JS接口列表
                });
                if(successCallBack){
                    successCallBack();
                }
            } else {
                errorAlert(data.msg);
                if(errorCallBack){
                    errorCallBack();
                }
            }
        }
    });
}


var doShareFriend=function(){
    wx.ready(function() {
        wx.checkJsApi({
            jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline'], // 需要检测的JS接口列表，所有JS接口列表见附录2,  
            success: function(res) {
                if (res.checkResult.onMenuShareAppMessage == false) {
                    alert("您的微信版本太低！");
                    return;
                }
            }
        });
        var img_url=getRootPath() +'/'+ $('#equipment-img').val();
        // alert($('.product-code').html());
        // alert($('.product-series').html());
        wx.onMenuShareAppMessage({
            title: $('#equipment-name').val(), // 分享标题
            desc: '我的装备库', // 分享描述
            link: window.location.href, // 分享链接
            imgUrl: img_url, // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                // $('.share-zhezhao').hide();
                // $('.share-arrow').hide();
            },
            cancel: function () {
                // $('.share-zhezhao').hide();
                // $('.share-arrow').hide();
            }
        });
        wx.onMenuShareTimeline({
            title: $('.product-code').html(), // 分享标题
            desc: $('.product-series').html(), // 分享描述
            link: window.location.href, // 分享链接
            imgUrl: img_url, // 分享图标
            success: function () {
                // $('.share-zhezhao').hide();
                // $('.share-arrow').hide();
            },
            cancel: function () {
                // $('.share-zhezhao').hide();
                // $('.share-arrow').hide();
            }
        });
    });
}